Page({
    data: {
        list: [],
        activeIndex: 0,
        tops: []
    },
    async onLoad() {
        try {
            let result = await wx.cloud.callFunction({ name: "dish" })
            this.setData({
                list: result.result.data
            })

            //获取右侧每个大块的高度
            const query = wx.createSelectorQuery()
            query.selectAll(".item").boundingClientRect()
            query.exec(res => {
                let tops = res[0].map(item => {
                    return item.top
                })
                this.setData({
                    tops
                })
            })
        } catch (error) {
            console.log(error)
        }

    },
    //点击左侧
    leftTap(e) {
        // console.log(e)
        let activeIndex = e.currentTarget.id;
        this.setData({
            activeIndex
        })

    },
    //右侧滚动
    rightScroll(e) {
        // console.log(e)
        let { scrollTop } = e.detail;
        let activeIndex = this.data.activeIndex;
        if (scrollTop >= this.data.tops[activeIndex + 1]) {
            this.setData({
                activeIndex: activeIndex + 1
            })
        }

        console.log(scrollTop,this.data.tops[activeIndex - 1])
        if (scrollTop-5 <= this.data.tops[activeIndex - 1]) {
            this.setData({
                activeIndex: activeIndex - 1
            })
        }


    }
})